Skip to content

fix(core): load the motion path plugin only for a page that tweens along a path - #8449

Merged
miguel-heygen merged 11 commits into
mainfrom
dharness/motionpath-preload
Nov 22, 2026
Merged

miguel-heygen merged 11 commits into
mainfrom
dharness/motionpath-preload

Conversation

@miguel-heygen

@miguel-heygen miguel-heygen commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

What

A preview no longer loads GSAP's MotionPath plugin for a page that provably cannot tween along a path. The preview builder (studio-server) reads the page and each project script it loads, and marks the page only when none names motionPath (quoted or not) and every other script is GSAP on its CDN. Any page it cannot prove, including one with a script from another host or a project script that tweens along a path, still preloads the plugin as before. When the preview's own plugin load fails, the page's GSAP fallback no longer loads it again from the CDN or reports "GSAP could not load ... so this preview's animations will not play".

Why

Since v0.9.80 (#8320) every sealed preview loads the plugin as soon as Studio connects its editing port, whether or not the film uses it. The plugin URL follows the film's GSAP version, so a film on a version the host does not bundle loads it from cdn.jsdelivr.net. Offline, or where the CDN is blocked, that load fails; the page's GSAP fallback takes it for one of the film's own GSAP scripts, tries the CDN again, and reports that the preview's animations will not play, while the film plays normally.

Repro: open a film whose GSAP is 3.12.5 and that has no motionPath in Studio's sealed preview with cdn.jsdelivr.net unreachable: Studio shows the error below. On v0.9.79 it loads nothing.

Related work

Refs #8320.

How

  • studio-server preview.ts provesNoPathTween: false when the page's text names motionPath, loads a child composition at run time, or has a base other than the project's preview base; then every <script> must be the HyperFrames runtime, GSAP at https://cdn.jsdelivr.net/npm/gsap@<version>/dist/<file>.js, or a project file whose text names no motionPath. A project file is resolved off the event loop with the same containment and private-file rules as resolveWithinProject: core resolveExistingWithinProjectOff (realpathOff on both sides, then realPathWithin, the comparison isSafePath now shares) and studio-server resolveExistingProjectFileOff (plus isPrivateProjectFileOff), so a link out of the project is not read. It must be a regular file of at most 4 MB, and any failed read counts as unknown. A module script, another host, a root path, a folder or a missing file makes it false, and inspection never fails the preview. Resolution, stat and read all run inside one budget, all scripts at once, with no synchronous fs call: at most 1 s and at most half of the time left before the preview request's own deadline (the root build's and a sub-composition's), so the preview keeps the rest. A scan that does not finish counts as unknown; with no time left there is no scan. The build runs the scan (provesNoPathTween) before the page's synchronous augmentation, on the main, sub-composition and saved-file fallback paths, and passes the answer in. A file's name is never trusted: an author's gsap.js is read like any other script. injectStudioPreviewAugmentations adds <meta name="hf-no-path-tween"> (NO_PATH_TWEEN_META in core gsapCdn.ts) when the scan proved it and Studio motion adds no script.
  • preloadMotionPath (core runtime/editing/softReload.ts), which both the sealed editing port and Studio's same-origin preview call, skips the plugin only when that meta is present. A page without it, from any other host too, preloads as main does, which covers a path tween an external script builds after connect.
  • namesMotionPath (core gsapCdn.ts) is the one text check, quoted keys included: the re-run, studio-server's plugin injection (htmlUsesMotionPath) and the builder's mark all use it.
  • The plugin's <script> carries data-hf-gsap-plugin (GSAP_PLUGIN_LOAD_ATTR). The preview's GSAP fallback (studio-server preview.ts) skips a script with it: the plugin's own loader already handles its failure (the re-run falls back to a reload).

Before

Studio (dev host, sealed preview) at this branch's merge-base, opening a plain GSAP 3.12.5 film with cdn.jsdelivr.net unresolvable: the plugin is requested from the CDN twice and the console-errors list shows the report.

Before

After

The same film at this branch (2d2449c): the builder marks the page, so no plugin request and no error.

After

Test plan

  • Unit tests added/updated
  • fails without the fix: packages/studio/src/utils/gsapSoftReloadWait.browser.test.ts "a path tween an external script builds after connect plays" with the script served as authored/gsap.js, sealed and unsealed (real Chrome; the tween is built after Studio connects, the test seeks to its end and expects x 50), fails with core's preload rule at 7bbb2c0 (a file named gsap.js counted as GSAP) and passes here. The same test with the script at path-tween.js passes on both.
  • fails without the fix: packages/studio-server/src/routes/preview.noPathTween.test.ts "holds for a page whose scripts are read and name no path" fails before the builder's proof existed, so every preview loaded the plugin; the file's other cases pin what is not proved: an authored gsap.js that tweens along a path, another host, a missing file, a module script, a quoted "motionPath" in the page.
  • fails without the fix: a folder as the script source threw EISDIR and failed the preview build at 2d2449c, and a link out of the project was read as a project script; preview.noPathTween.test.ts "fails for a script it cannot read: ... a folder" and "fails for a script that links out of the project" pin both.
  • fails without the fix: node scripts/check-studio-server-sync-fs.mjs counted 9 synchronous fs calls in routes/preview.ts at c2e76ec, over its 7; it passes here at 7. "fails when resolving its path / reading it does not answer within the budget" pin the time budget.
  • fails without the fix: preview.scanDeadline.test.ts serves a sub-composition with a 200 ms request deadline whose script lookup never answers: at e7f08a6 the route answered after 1,010 ms (the scan's own 1 s); here it answers 200 within 500 ms (about 105 ms).
  • fails without the fix: preview.noPathTween.test.ts "resolves project scripts without a synchronous realpath" counts calls to fs.realpathSync.native during a scan: 4 with the scan at a331121, 0 here.
  • fails without the fix: packages/studio-server/src/routes/preview.test.ts "leaves the preview's own plugin load to its loader: no fallback load, no report" fails with main's preview.ts.
  • In real Chrome, "a page the preview builder marked as path-free requests no plugin" pins the plain case; gsapSoftReload.test.ts pins the mark both ways and that the plugin script carries data-hf-gsap-plugin.
  • On the devbox at eef5e70: the six named test files (core safePath.test.ts included) 3 runs each, the covering tests, tsc in core, studio and studio-server, the Fallow audit and the pre-push hook pass.
  • Manual testing performed: the Before and After above, Studio's dev host in Chromium on Linux with the CDN unresolvable. The walk fixture Desktop's import-bare-folder opens (its own gsap.min.js beside an inline timeline) meets the rule, so it gets the mark.
  • Comments follow CONTRIBUTING.md "Comments"

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Preserve MotionPath for compositions whose tween lives in an external script (packages/core/src/runtime/editing/softReload.ts:467). The gate only inspects inline script text. In a Chromium probe using the preview bundle, real GSAP, and a sealed editing port, the same external tween moved the element 50 px on the previous version and 0 px here. The new preview made no plugin request and GSAP reported a missing plugin. Account for known MotionPath usage in external composition scripts while keeping the no-motion preview free of plugin requests.

The shared text check also misses a quoted "motionPath" property. A small direct probe reproduced that. Update the same-origin preload comment to reflect that a first path introduced by editing may now wait for the plugin.

All 28 focused tests passed. The local Chromium probe also confirmed that a plain tween makes no plugin request, an inline path still plays, and an offline load started by editing returns cannot-soft-reload without the generic fallback report. I did not run a full Studio editing session.

— tai (automated review)

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 271 (base branch 271), smooth 86 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (0)

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Thanks. All three at b3a2845:

  • External script: the preload now also looks at the page's registered timelines (window.__timelines) for a tween whose vars.motionPath is set. GSAP keeps a tween's vars even when the plugin is missing, so an external script's path tween is seen with no fetch (a sealed frame has an opaque origin and cannot read its own <script src>). The real-Chrome test serves the tween from an external .js and checks the plugin is requested and registered, sealed and unsealed; it fails with core back to the inline-only check.
  • Quoted "motionPath": namesMotionPath in core gsapCdn.ts takes quoted keys, and it is now the only copy: the re-run, the preload and studio-server's page injection (htmlUsesMotionPath) all use it.
  • Studio's same-origin preload comment now says a first path added by an edit waits for the plugin on its re-run.

One thing I could not reproduce: in Studio's Chrome harness the external tween stays at x 0 after a seek to its end even with the plugin loaded at connect, since the runtime renders it before the plugin lands. So the test pins the plugin request, not the 50 px. If your probe loaded the page differently (connect before the first render?), I'd like to match it.

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Preserve path tweens created after preview connect (packages/core/src/runtime/editing/softReload.ts:475). The added scan sees tweens already registered at the moment Studio connects. It misses an external script that creates its first path tween later during normal playback, with no script edit to trigger soft reload. In a fresh sealed Chromium probe with real GSAP, that tween moved 50 px with the main runtime and 0 px with this head. Main requested the plugin once. The new head made no request and GSAP reported a missing plugin. The new eager external-script test creates its tween before connect and asserts the script loads. In my probe that eager case loaded the plugin but moved 0 px on both runtimes. Please add a playback assertion for the late case and keep the plain-preview no-fetch assertion.

Required captures. The latest “Studio and player captures” job failed because Before and After sections are missing. Include captures of the changed preview behavior.

The core build and 119 focused Studio tests passed. The playback comparison used a local Chromium fixture, without a live CDN outage.

— tai (automated review)

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Right, the timeline scan only saw tweens that existed at connect. At 7bbb2c0 the rule is the other way round: the preview skips the plugin only when it knows no script can build a path tween (every inline script read clean, and every external script is the HyperFrames runtime or a GSAP library file). An author's external script, which a sealed frame cannot read, keeps the preload, as on main.

  • Late case: gsapSoftReloadWait.browser.test.ts "a path tween an external script builds after connect plays" (sealed and unsealed) builds the tween after Studio connects, seeks to its end and expects x 50. It passes here and fails with b3a2845's rule.
  • Plain preview: "a page with no path tween requests no plugin" still holds in real Chrome, and the unit test now covers a page with GSAP's own files and the runtime.
  • Captures: Before and After are in the description (Studio's sealed preview, CDN unreachable): the merge-base shows the "animations will not play" report from two plugin loads; this branch makes no request.

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Identify known library scripts by their source. In packages/core/src/runtime/editing/softReload.ts:464, any external file named gsap.js or gsap.min.js is treated as the GSAP library. A composition’s own animation bootstrap can have either name. In the sealed Chromium fixture, the late external tween now moves 50 px when its script is named external-tween.js. Serving the exact same authored script at /authored/gsap.js makes the head skip the plugin and leaves the element at 0 px. The main runtime requests the plugin and moves 50 px in that case. Use known library URLs or provenance from the preview builder, and keep the conservative preload for unrecognized sources.

Review gate. Keep a dedicated fails without the fix: line in the PR body. The current entries put the round in parentheses before the colon, so none has the required prefix. The latest required capture check passed with the new Before and After evidence.

Core built successfully. All 283 focused Studio and preview-route tests passed. The additional local Chromium probe reproduced the filename collision. The plain preview made zero plugin requests.

— tai (automated review)

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Keep optional script classification from failing the preview (packages/studio-server/src/routes/preview.ts:207). A project script source can exist but still be unreadable or be something other than a regular file. The new synchronous read throws in that case, including in the saved-file fallback that calls the same augmentation. In a benign local fixture, a script URL pointing at an existing directory throws EISDIR instead of leaving the page unmarked. Treat failed inspection as unknown. Use the project asset boundary for inspection and restrict it to bounded reads of regular files. The current root check is lexical and does not establish confinement for the resolved file.

Review gate. The body still has fails without the fix (last commit): and similar entries. Put the commit qualifiers after the literal fails without the fix: prefix.

The original authored gsap.js case now moves 50 px in sealed Chromium and the capture check passed. The core build and 166 focused preview-route tests passed. The additional route fixture reproduced the thrown read.

— tai (automated review)

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Fixed at c2e76ec. The builder's script read can no longer fail the preview: a project script is resolved with resolveWithinProject (the project's real-path boundary, so a link out of the project is not read), must be a regular file of at most 4 MB, and any failed read counts as unknown, which leaves the page unmarked and the plugin preloaded. preview.noPathTween.test.ts adds a folder as the script source (EISDIR before) and a link out of the project; both fail at 2d2449c and pass here. The body's red-proof lines now start with the literal prefix.

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 — The new preview scan blocks the build’s sync-filesystem gate. packages/studio-server/src/routes/preview.ts:208 adds synchronous stat and read calls on the preview route. node scripts/check-studio-server-sync-fs.mjs reports 9 synchronous calls against 7 allowed, matching the failed Build step on this head. Please move script inspection into the bounded asynchronous preview build and keep falling back to preload when the scan cannot complete.

The two targeted preview suites passed (168 tests). The PR body names the failing-before tests.

— tai (automated review)

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Fixed at a331121. The scan now runs in the async build, before the page's synchronous augmentation, on the main, sub-composition and saved-file fallback paths, and passes its answer in. It reads with fs/promises, all scripts at once, within a 1 s budget, and a scan that fails or doesn't finish leaves the page unmarked, so it preloads. check-studio-server-sync-fs.mjs counts 7 sync calls in routes/preview.ts again (9 at c2e76ec). A new case pins the budget: a read that never answers leaves the page unmarked within it. The body's red-proof lines start with the literal prefix.

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 — The script scan still resolves paths synchronously on the server thread. In routes/preview.ts:219, resolveWithinProject runs before the first await. Its containment and private-path checks call synchronous realpath through helpers/safePath.ts and core’s safePath.ts. Each script begins that work during the map at line 253, before the one-second timer starts. A slow or stalled volume can therefore still delay the whole server despite the async stat and file read. The sync-fs gate passes because it counts direct calls in the route, and the timeout test delays the read only after resolution has already finished.

Please move the entire scan into the preview worker or use a bounded asynchronous path resolver, retaining both containment and private-path checks. Extend the timeout test to cover a delayed resolution as well as a delayed read. The sync-fs gate and both focused suites passed locally (169 tests).

— tai (automated review)

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Fixed at e7f08a6. Script paths now resolve off the event loop with the same rules as resolveWithinProject: core resolveExistingWithinProjectOff (realpathOff on both sides, then realPathWithin, the comparison isSafePath now shares, so the two can't drift) and studio-server resolveExistingProjectFileOff, which adds the private-file check through isPrivateProjectFileOff. Resolution, stat and read all run inside the one budget, which starts before any script is looked at.

Tests: "resolves project scripts without a synchronous realpath" counts fs.realpathSync.native calls during a scan (4 at a331121, 0 here), and the budget case now runs twice, once with resolution stalled and once with the read stalled. Both leave the page unmarked within the budget. Core's safePath.test.ts covers the async resolver: an in-project file, .. and a link out.

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 — The optional script scan can outrun the preview request’s deadline. The async resolver fixes the synchronous filesystem issue. The sub-composition route at routes/preview.ts:847 still awaits provesNoPathTween on a fresh one-second timer after the route has already started its absolute deadline. During that await, nothing enforces the request’s earlier deadline.

I warmed the build worker and called the real sub-composition route with a 200 ms deadline. With a local script lookup held in the async resolver, the route returned 200 after 1,007 ms. The optional proof should use the remaining request budget, with the ordinary preview taking precedence. Please add a route-level test with a shorter request budget than the scan’s own budget. The resolver tests and sync-fs gate pass.

— tai (automated review)

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Fixed at eef5e70. The scan now gets the preview request's own deadline (the root build's, or the sub-composition's) and uses at most half of the time left, capped at 1 s, so the preview keeps the rest. With no time left it doesn't scan, and the page preloads. The saved-file fallback has no request deadline and keeps the 1 s cap.

preview.scanDeadline.test.ts is the route-level case: a sub-composition with a 200 ms request deadline and a script lookup that never answers. At e7f08a6 the route answered after 1,010 ms. Here it answers 200 within 500 ms (about 105 ms), with the build worker warm, as in your probe.

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The optional MotionPath scan now takes at most half the remaining root or sub-composition deadline. A stalled lookup leaves the normal preload in place. The held-lookup route regression, the preview suites, the sync-fs gate, and the required CI checks passed.

— tai (automated review)

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Thanks. One fix after the approval, at e32dbd8: core's Windows tests failed at eef5e70 because the async path check threw for a path that does not resolve (../../etc/passwd is missing there) instead of answering null. resolveExistingWithinProjectOff now fails closed like isSafePath, and its test escapes to a file that exists on every OS. It fails at eef5e70 with the same ENOENT and passes here. The Windows studio shards passed at eef5e70.

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The async resolver now returns null when either path cannot resolve and still rejects a resolved path outside the project. The test now uses an existing sibling fixture and includes a missing-file case that reproduces ENOENT with the previous implementation. All 378 focused tests, the sync-fs gate, the Windows core job and the required checks passed.

— tai (automated review)

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 22, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 22, 2026
@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 22, 2026
Merged via the queue into main with commit 4157992 Nov 22, 2026
101 checks passed
@miguel-heygen
miguel-heygen deleted the dharness/motionpath-preload branch November 22, 2026 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants